home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1996
/
MacHack 1996.toast
/
Hacks
/
Hacks ’87
/
Source ƒ.sit
/
Source ƒ
/
modula 2 ƒ
/
Draw3D (M2)
/
ThreeDee.MOD
< prev
next >
Wrap
Text File
|
1984-12-31
|
2KB
|
88 lines
IMPLEMENTATION MODULE ThreeDee;
FROM QuickDrawTypes IMPORT Point;
FROM MathLib1 IMPORT sin, cos, entier;
FROM MathConst IMPORT RadConst;
FROM ThreeDee IMPORT Point3D;
VAR
cosRX, cosRY, cosRZ, sinRX, sinRY, sinRZ: REAL;
scalX, scalY, scalZ: REAL;
tranX, tranY, tranZ: REAL;
projectionZ, srceZ: REAL;
xiXo, xiYo, xiZo,
yiXo, yiYo, yiZo,
ziXo, ziYo, ziZo: REAL;
PROCEDURE SetPoint3D( x, y, z: REAL; VAR p: Point3D );
BEGIN
WITH p DO X:=x; Y:=y; Z:=z; END;
END SetPoint3D;
PROCEDURE SetRSM; (* calculate rotation+scale transform *)
BEGIN
xiXo:=scalX * cosRY*cosRZ;
xiYo:=scalX * cosRY*sinRZ;
xiZo:=scalX * (-sinRY);
yiXo:=scalY * (sinRX*sinRY*cosRZ - cosRX*sinRZ);
yiYo:=scalY * (cosRX*cosRZ + sinRX*sinRY*sinRZ);
yiZo:=scalY * sinRX*cosRY;
ziXo:=scalZ * (sinRX*sinRZ + cosRX*sinRY*cosRZ);
ziYo:=scalZ * (cosRX*sinRY*sinRZ - cosRZ*sinRX);
ziZo:=scalZ * cosRX*cosRY;
END SetRSM;
PROCEDURE SetRot( rotX, rotY, rotZ: REAL );
BEGIN
rotX:=RadConst*rotX; cosRX:=cos( rotX ); sinRX:=sin( rotX );
rotY:=RadConst*rotY; cosRY:=cos( rotY ); sinRY:=sin( rotY );
rotZ:=RadConst*rotZ; cosRZ:=cos( rotZ ); sinRZ:=sin( rotZ );
SetRSM;
END SetRot;
PROCEDURE SetScale( scaleX, scaleY, scaleZ: REAL );
BEGIN
scalX:=scaleX; scalY:=scaleY; scalZ:=scaleZ;
SetRSM;
END SetScale;
PROCEDURE SetTranslation( transX, transY, transZ: REAL );
BEGIN
tranX:=transX; tranY:=transY; tranZ:=transZ;
END SetTranslation;
PROCEDURE SetPerspective( screenZ, sourceZ: REAL );
BEGIN
projectionZ:=screenZ-sourceZ;
srceZ:=sourceZ;
END SetPerspective;
PROCEDURE TransformSRT( in: Point3D; VAR out: Point3D );
BEGIN
WITH in DO
out.X:=tranX + X*xiXo + Y*yiXo + Z*ziXo;
out.Y:=tranY + X*xiYo + Y*yiYo + Z*ziYo;
out.Z:=tranZ + X*xiZo + Y*yiZo + Z*ziZo;
END; (*WITH*)
END TransformSRT;
PROCEDURE Project( in: Point3D; VAR out: Point );
VAR
effectiveZ: REAL;
BEGIN
WITH in DO
effectiveZ:=Z-srceZ;
IF ABS(effectiveZ) < 0.0001 THEN effectiveZ:=0.0001; END;
out.h:=entier(projectionZ*X/effectiveZ);
out.v:=entier(projectionZ*Y/effectiveZ);
END; (*WITH*)
END Project;
BEGIN
SetTranslation( 0.0, 0.0, 0.0 );
SetPerspective( 100.0, -100.0 );
scalX:=1.0; scalY:=1.0; scalZ:=1.0;
SetRot( 0.0, 0.0, 0.0 );
END ThreeDee.